import argparse
import utis
from config_utils import config


class ArgParse:
    def __init__(self):
        self.parser = argparse.ArgumentParser()
        self.subparser = self.parser.add_subparsers(required=True)
        self.__add_beautify_parsr()
        self.__add_pre_parser()

    def __add_beautify_parsr(self):
        beautify_parser = self.subparser.add_parser("beautify", help="美化")
        beautify_parser.add_argument("--linux_name", choices=["arch", "fedora"], required=True)
        beautify_parser.set_defaults(action=self.__beautify_handle)

    def __add_pre_parser(self):
        pre_parser = self.subparser.add_parser("pre", "安装准备")
        pre_parser.add_argument("--linux_name", type=str, choices=["arch,fedora"], required=True)
        pre_parser.add_argument("--card", type=str, choices=["AMD", "NVIDIA"], required=True)
        pre_parser.set_defaults(action=self.__pre_handle)

    @staticmethod
    def __beautify_handle(args):
        utis.exec_command(args, config.icon)

    @staticmethod
    def __pre_handle(args):
        utis.print_log(args.linux_name)
        if args.card == "NVIDIA":
            utis.exec_command(args, config.nvidia)
        utis.exec_command(args, config.app)
        utis.exec_command(args, config.sys)
